<!DOCTYPE html> <html><!--
 Archive processed by SingleFile 
 url: https://mp.weixin.qq.com/s/nbelBO7xS15y_0MvPtS5OQ 
 saved date: Thu Nov 21 2019 14:13:25 GMT+0800 (中国标准时间) 
--><meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover">
<meta name=apple-mobile-web-app-capable content=yes>
<meta name=apple-mobile-web-app-status-bar-style content=black>
<meta name=format-detection content="telephone=no">
<meta name=description content=面对十亿级别的海量数据，ES如何做到毫秒级查询？>
<meta name=author content=中华石杉>
<meta property=og:title content=查询亿级数据毫秒级返回！牛逼哄哄的ElasticSearch是如何做到的？>
<meta property=og:url content="http://mp.weixin.qq.com/s?__biz=MzI3NjU2ODA5Mg==&amp;mid=2247484607&amp;idx=1&amp;sn=d04e06f67a240abb32fd94aa93460064&amp;chksm=eb72c5ccdc054cda041cbd54bf43aa3d48c3233fcb7d7197e00395b8afeae85c7fe475f835f3#rd">
<meta property=og:image content="http://mmbiz.qpic.cn/mmbiz_jpg/M7B64fHXISv6bU4Cz0u12c947HppvvUHE6DqPMMoKvLk5f4TMHqWnDiaA2zyUiabItpU5WzhV1UaH5BDAboYSslQ/0?wx_fmt=jpeg">
<meta property=og:description content=面对十亿级别的海量数据，ES如何做到毫秒级查询？>
<meta property=og:site_name content=微信公众平台>
<meta property=og:type content=article>
<meta property=og:article:author content=中华石杉>
<meta property=twitter:card content=summary>
<meta property=twitter:image content="http://mmbiz.qpic.cn/mmbiz_jpg/M7B64fHXISv6bU4Cz0u12c947HppvvUHE6DqPMMoKvLk5f4TMHqWnDiaA2zyUiabItpU5WzhV1UaH5BDAboYSslQ/0?wx_fmt=jpeg">
<meta property=twitter:title content=查询亿级数据毫秒级返回！牛逼哄哄的ElasticSearch是如何做到的？>
<meta property=twitter:creator content=中华石杉>
<meta property=twitter:site content=微信公众平台>
<meta property=twitter:description content=面对十亿级别的海量数据，ES如何做到毫秒级查询？>
<title>查询亿级数据毫秒级返回！牛逼哄哄的ElasticSearch是如何做到的？</title>
<style media>.rich_media_inner{overflow-wrap:break-word;hyphens:auto}.rich_media_area_primary{padding:calc(20px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 12px calc(16px + env(safe-area-inset-left))}.rich_media_area_extra{padding:0 calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left))}html{line-height:1.6}body{color:#333;background-color:#f2f2f2;letter-spacing:.034em}h2{font-weight:400}*{margin:0;padding:0}a{-webkit-tap-highlight-color:rgba(0,0,0,0)}.rich_media_title{font-size:22px;line-height:1.4;margin-bottom:14px}@supports(-webkit-overflow-scrolling:touch){.rich_media_title{font-weight:700}}.rich_media_meta_list{margin-bottom:22px;line-height:20px;font-size:0;overflow-wrap:break-word;word-break:break-all}.rich_media_meta_list em{font-style:normal}.rich_media_meta{display:inline-block;vertical-align:middle;margin:0 10px 10px 0;font-size:15px;-webkit-tap-highlight-color:rgba(0,0,0,0)}.rich_media_meta_text{color:rgba(0,0,0,0.3)}.rich_media_meta_nickname{position:relative}.rich_media_content{overflow:hidden;color:#333;font-size:17px;overflow-wrap:break-word;hyphens:auto;text-align:justify;z-index:0}.rich_media_content *{max-width:100% !important;box-sizing:border-box !important;overflow-wrap:break-word !important}.rich_media_content p{clear:both;min-height:1em}@media screen and (min-width:1024px){.rich_media_area_primary_inner,.rich_media_area_extra_inner{max-width:677px;margin-left:auto;margin-right:auto}.rich_media_area_primary{padding-top:32px}}blockquote{padding-left:10px;border-left:3px solid #dbdbdb;color:rgba(0,0,0,0.5);font-size:15px;padding-top:4px;margin:1em 0}.appmsg_skin_default .rich_media_area_primary{background-color:#fff}.appmsg_style_default .rich_media_tool{padding-top:15px}.read-more__area{margin:30px 0}html,body{height:100%}</style>
<!--[if lt IE 9]>
<link rel="stylesheet" type="text/css" href="//res.wx.qq.com/mmbizwap/zh_CN/htmledition/style/page/appmsg_new/pc492bcc.css">
<![endif]-->
<style id=page/appmsg_new/not_in_mm.css>.weui-flex{display:flex}.weui-flex__item{-webkit-box-flex:1;flex:1 1 0%}html{text-size-adjust:100%}body{line-height:1.6;font-family:-apple-system-font,BlinkMacSystemFont,"Helvetica Neue","PingFang SC","Hiragino Sans GB","Microsoft YaHei UI","Microsoft YaHei",Arial,sans-serif;font-size:16px}body,h2,p,ul{margin:0}a{color:#576b95;text-decoration:none}body,html{-webkit-appearance:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}@media(orientation:portrait){@-webkit-keyframes opr_fade_out{0%{opacity:1}100%{opacity:0}}@-webkit-keyframes opr_fade_in{0%{opacity:0}100%{bottom:0;opacity:1}}}@-webkit-keyframes opr_fade_out{0%{opacity:1}100%{opacity:0}}@-webkit-keyframes opr_fade_in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes opacity-60-25-0-12{0%{opacity:.25}0.01%{opacity:.25}0.02%{opacity:1}60.01%{opacity:.25}100%{opacity:.25}}@-webkit-keyframes opacity-60-25-1-12{0%{opacity:.25}8.34333%{opacity:.25}8.35333%{opacity:1}68.3433%{opacity:.25}100%{opacity:.25}}@-webkit-keyframes opacity-60-25-2-12{0%{opacity:.25}16.6767%{opacity:.25}16.6867%{opacity:1}76.6767%{opacity:.25}100%{opacity:.25}}@-webkit-keyframes opacity-60-25-3-12{0%{opacity:.25}25.01%{opacity:.25}25.02%{opacity:1}85.01%{opacity:.25}100%{opacity:.25}}@-webkit-keyframes opacity-60-25-4-12{0%{opacity:.25}33.3433%{opacity:.25}33.3533%{opacity:1}93.3433%{opacity:.25}100%{opacity:.25}}@-webkit-keyframes opacity-60-25-5-12{0%{opacity:.270958}41.6767%{opacity:.25}41.6867%{opacity:1}1.67667%{opacity:.25}100%{opacity:.270958}}@-webkit-keyframes opacity-60-25-6-12{0%{opacity:.375125}50.01%{opacity:.25}50.02%{opacity:1}10.01%{opacity:.25}100%{opacity:.375125}}@-webkit-keyframes opacity-60-25-7-12{0%{opacity:.479292}58.3433%{opacity:.25}58.3533%{opacity:1}18.3433%{opacity:.25}100%{opacity:.479292}}@-webkit-keyframes opacity-60-25-8-12{0%{opacity:.583458}66.6767%{opacity:.25}66.6867%{opacity:1}26.6767%{opacity:.25}100%{opacity:.583458}}@-webkit-keyframes opacity-60-25-9-12{0%{opacity:.687625}75.01%{opacity:.25}75.02%{opacity:1}35.01%{opacity:.25}100%{opacity:.687625}}@-webkit-keyframes opacity-60-25-10-12{0%{opacity:.791792}83.3433%{opacity:.25}83.3533%{opacity:1}43.3433%{opacity:.25}100%{opacity:.791792}}@-webkit-keyframes opacity-60-25-11-12{0%{opacity:.895958}91.6767%{opacity:.25}91.6867%{opacity:1}51.6767%{opacity:.25}100%{opacity:.895958}}@-webkit-keyframes loading{0%{transform:rotate3d(0,0,1,0)}100%{transform:rotate3d(0,0,1,360deg)}}@keyframes loading{0%{transform:rotate3d(0,0,1,0)}100%{transform:rotate3d(0,0,1,360deg)}}.article_extend_area{padding:30px 0 0}.article_extend_area:empty{display:none}@supports(-webkit-overflow-scrolling:touch){.reward_button{font-weight:700}}.rich_media_extra{position:relative}.top_banner{background-color:#fff}.ct_mpda_wrp{margin:38px 0 20px}.article_modify_area_primary{margin-top:16px;text-align:left;font-size:15px}.like_btn{-webkit-appearance:none;-webkit-tap-highlight-color:rgba(0,0,0,0);outline:0;background-color:transparent;border:0;display:inline-block;vertical-align:middle;padding:0;font-size:15px;font-family:inherit;line-height:2.13333;color:#576b95}.like_btn::before{font-size:16px;content:"";display:inline-block;width:1em;height:1.125em;vertical-align:middle;margin-top:-0.25em;margin-right:.05em;background:url("data:image/svg+xml;charset=utf8, %3Csvg width='18' height='20' viewBox='0 0 18 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.485 3.785l2.506-2.477a1.674 1.674 0 0 1 2.352 0l2.505 2.477 3.423.908a1.653 1.653 0 0 1 1.18 2.026l-.917 3.382.918 3.384a1.652 1.652 0 0 1-1.18 2.024l-3.399.902-2.53 2.493a1.674 1.674 0 0 1-2.352 0l-2.506-2.477-3.423-.908a1.653 1.653 0 0 1-1.18-2.026l.917-3.383-.918-3.392a1.652 1.652 0 0 1 1.18-2.025l3.424-.908zm.836 1.447l.006 2.298c0 .59-.317 1.138-.828 1.438l-2.015 1.143 2.005 1.136c.517.29.838.841.838 1.435l-.006 2.298 2.01-1.156a1.667 1.667 0 0 1 1.675-.003l2.007 1.154-.007-2.302c0-.583.319-1.13.829-1.43l2.014-1.142-2.005-1.136a1.647 1.647 0 0 1-.838-1.435l.007-2.298-2.01 1.156a1.65 1.65 0 0 1-1.67.001L6.321 5.232zm-1.094 2.3L5.22 4.994l-2.878.763a.552.552 0 0 0-.398.674l.77 2.851 2.23-1.264a.573.573 0 0 0 .283-.486zm-.278 4.673L2.714 10.94l-.77 2.84a.553.553 0 0 0 .399.676l2.877.763.007-2.537a.548.548 0 0 0-.278-.476zm3.935 2.57l-2.216 1.274 2.096 2.073c.222.22.583.22.806 0l2.103-2.073-2.214-1.274a.57.57 0 0 0-.575 0zm4.222-2.104l.007 2.538 2.879-.763a.552.552 0 0 0 .398-.674l-.771-2.843-2.23 1.265a.57.57 0 0 0-.283.477zm.279-4.664l2.234 1.266.77-2.84a.553.553 0 0 0-.399-.676l-2.877-.763-.007 2.537c0 .196.107.38.279.476zm-4.501-2.57c.176.104.39.104.566 0l2.215-1.274L9.57 2.09a.574.574 0 0 0-.805 0L6.668 4.163l2.216 1.274z' fill='%23576B95' fill-rule='evenodd'/%3E%3C/svg%3E") 0 0 / 1em no-repeat transparent}.like_num{font-size:15px;margin-left:.2em}.like_comment_wrp{font-size:17px;margin-top:9px;margin-bottom:8px;position:relative;z-index:1}.like_comment_wrp::before,.like_comment_wrp::after{content:"";display:inline-block;width:0;height:0;border-width:0 7px 7px;border-style:dashed dashed solid;border-color:transparent transparent rgba(0,0,0,0.03);position:absolute;top:-7px;right:28px}.like_comment_wrp::after{border-bottom-color:#f7f7f7;top:-6px}.like_comment_inner{background-color:rgba(0,0,0,0.03);border-radius:4px;overflow:hidden;padding:24px 16px;display:flex;-webkit-box-align:center;align-items:center;text-align:center}.like_comment_primary_wrp{font-size:16px;margin-top:9px;margin-bottom:4px;background-color:#fff;z-index:21}.like_comment_primary_wrp::before,.like_comment_primary_wrp::after{content:"";display:inline-block;width:0;height:0;border-width:0 7px 7px;border-style:dashed dashed solid;border-color:transparent transparent #fff;position:absolute;top:-7px;right:28px}.like_comment_primary_wrp::after{border-bottom-color:#fff;top:-6px}.like_comment_primary_wrp.editing{position:fixed;top:10px;bottom:0;left:0;right:0;margin:0}.like_comment_primary_wrp.editing::before,.like_comment_primary_wrp.editing::after{display:none}.like_comment_primary_mask{position:fixed;z-index:20;top:0;left:0;bottom:0;right:0;background-color:rgba(0,0,0,0.2)}@-webkit-keyframes weuiLoading{0%{transform:rotate3d(0,0,1,0)}100%{transform:rotate3d(0,0,1,360deg)}}@keyframes weuiLoading{0%{transform:rotate3d(0,0,1,0)}100%{transform:rotate3d(0,0,1,360deg)}}@-webkit-keyframes slidein{0%{transform:translateX(-50%)}100%{transform:translateX(0)}}@keyframes slidein{0%{transform:translateX(-50%)}100%{transform:translateX(0)}}.mpda_bottom_container{position:relative}.rich_media_tool{overflow:hidden;line-height:32px}.rich_media_tool .meta_primary{float:left}.rich_media_tool .meta_extra{float:right}.rich_media_tool .meta_praise{text-align:right}.media_tool_meta i{vertical-align:0;position:relative;top:1px}.meta_praise{-webkit-tap-highlight-color:rgba(0,0,0,0);outline:0}.meta_praise .praise_num{display:inline-block;vertical-align:top}.meta_praise:hover{cursor:pointer}.icon_praise_gray{background:url("") 0 0 / 100% no-repeat transparent;display:inline-block}.rich_media_tool{font-size:15px}.rich_media_tool .meta_primary{margin-right:16px}.rich_media_tool .meta_extra{margin-left:16px;color:#576b95}.rich_media_tool .meta_praise{min-width:2.5em}.rich_media_tool .meta_praise i{margin-right:5px}.icon_praise_gray{background-image:url("data:image/svg+xml;charset=utf8, %3Csvg width='16' height='16' viewBox='0 0 16 16' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2.5 6.988h-.003c-.095-.01-.167-.022-.125-.022H1.75c-.343 0-.75.39-.75.7v6.73c0 .31.27.57.611.57H2.5V7.01a.51.51 0 0 1 0-.022zm1 .003a.55.55 0 0 1 0 .02v7.955h7.414c.748 0 1.395-.361 1.773-1.324a37.17 37.17 0 0 0 1.115-2.57c.219-.564.413-1.11.575-1.627.247-.785.413-1.48.484-2.058.073-.595-.565-1.021-1.236-1.021h-4.97l.102-.586.18-1.027.13-.55a35.058 35.058 0 0 0 .245-1.128c.212-1.098-.483-2.019-1.238-2.067-.74-.048-1.1.111-1.104.562-.008 1.276-.45 2.805-1.252 4.129-.357.589-.899.965-1.56 1.16-.217.065-.438.107-.658.132zm6.345-1.625h3.78c1.19 0 2.393.804 2.229 2.143-.08.646-.26 1.397-.523 2.235-.17.54-.37 1.107-.597 1.69a38.158 38.158 0 0 1-1.133 2.61c-.525 1.346-1.557 1.922-2.687 1.922H1.61c-.886 0-1.611-.698-1.611-1.57v-6.73c0-.871.864-1.7 1.75-1.7l.719.009A3.285 3.285 0 0 0 3.876 5.9c.435-.13.769-.361.986-.72.71-1.171 1.102-2.525 1.108-3.618C5.978.338 6.901-.07 8.14.01c1.36.088 2.48 1.57 2.155 3.255a36.012 36.012 0 0 1-.253 1.167l-.124.52-.072.414z' fill='%23576B95' fill-rule='nonzero'/%3E%3C/svg%3E");font-size:16px;width:1em;height:1em;background-size:1em}.praise_num{color:#576b95}a,button{cursor:pointer}.rich_media_extra{overflow:hidden}.rich_media_extra_discuss{padding-top:0}.praise_num:empty{margin-left:-3px}.comment_primary_emotion_panel_wrp{position:absolute;z-index:1;padding-top:8px;padding-bottom:16px}.comment_primary_emotion_panel{background:#fff;box-shadow:rgba(0,0,0,0.16) 0 2px 8px 0;border-radius:4px;width:376px;height:216px;overflow-y:auto}.tips_global_primary{color:rgba(0,0,0,0.3)}.weui-dialog{position:fixed;z-index:5000;top:50%;left:16px;right:16px;transform:translate(0,-50%);background-color:#fff;text-align:center;border-radius:12px;overflow:hidden;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;max-height:90%}@media screen and (min-width:352px){.weui-dialog{width:320px;margin:0 auto}}.weui-toast{position:fixed;z-index:5000;width:120px;height:120px;top:40%;left:50%;transform:translate(-50%,-50%);background:rgba(17,17,17,0.7);text-align:center;border-radius:5px;color:#fff;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;-webkit-box-align:center;align-items:center;-webkit-box-pack:center;justify-content:center}.weui-mask{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0;background:rgba(0,0,0,0.6)}.weui-mask_transparent{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0}@-webkit-keyframes weuiLoading{0%{transform:rotate3d(0,0,1,0)}100%{transform:rotate3d(0,0,1,360deg)}}@keyframes weuiLoading{0%{transform:rotate3d(0,0,1,0)}100%{transform:rotate3d(0,0,1,360deg)}}@media screen and (max-width:1023px){.profile_container{display:none !important}}.weui-desktop-popover{white-space:normal;overflow-wrap:break-word;hyphens:auto;z-index:500;color:#353535;line-height:1.6;background:#fff;border-radius:2px}.weui-desktop-popover::before{content:" ";width:8px;height:8px;background-color:#fff;box-shadow:#d4d4d4 0 2px 10px 0;transform:matrix(0.71,0.71,-0.71,0.71,0,0);position:absolute}.weui-desktop-popover::after{content:" ";background-color:#fff;position:absolute}.weui-desktop-popover_img-text{text-align:center}.weui-desktop-popover_pos-up-center{margin-top:16px}.weui-desktop-popover_pos-up-left::before,.weui-desktop-popover_pos-up-center::before,.weui-desktop-popover_pos-up-right::before{top:-4px}.weui-desktop-popover_pos-up-left::after,.weui-desktop-popover_pos-up-center::after,.weui-desktop-popover_pos-up-right::after{height:10px;top:0;left:0;right:0}.weui-desktop-popover_pos-up-center::before,.weui-desktop-popover_pos-down-center::before{margin-left:-4px}.weui-desktop-popover{position:absolute;padding:14px;box-shadow:none;border:1px solid #d9dadc;width:182px;box-sizing:border-box}.weui-desktop-popover::before{box-shadow:none;border:1px solid #d9dadc}.not_in_mm .rich_media_meta_list{position:relative;z-index:1}.not_in_mm .rich_media_content{position:relative}.not_in_mm .profile_container{width:535px;position:absolute;top:100%;left:0;margin-top:10px;font-size:14px}.not_in_mm .profile_inner{position:relative;padding:30px 22px 36px 144px;background-color:#fff;border:1px solid #d9dadc}.not_in_mm .profile_arrow_wrp{position:absolute;left:22px;top:-8px}.not_in_mm .rich_media_inner{position:relative}.not_in_mm .qr_code_pc_outer{position:fixed;left:0;right:0;top:20px;color:#717375;text-align:center;display:none !important}.not_in_mm .qr_code_pc_inner{position:relative;width:740px;margin-left:auto;margin-right:auto}.not_in_mm .qr_code_pc{position:absolute;right:-140px;top:0;width:140px;padding:16px;border:1px solid #d9dadc;background-color:#fff;overflow-wrap:break-word;word-break:break-all}.not_in_mm .qr_code_pc p{font-size:14px;line-height:20px}.not_in_mm .qr_code_pc_img{width:102px;height:102px}@media screen and (min-width:1024px){.not_in_mm .qr_code_pc_outer{top:32px;display:block !important}}.not_in_mm .qr_code_pc{box-sizing:border-box}</style><link rel="shortcut icon" type=image/x-icon href=""></head>
 <body id=activity-detail class="zh_CN mm_appmsg appmsg_skin_default appmsg_style_default not_in_mm">
 
 
 
<div id=js_article class=rich_media>
 
 <div id=js_top_ad_area class=top_banner></div>
 
 <div class=rich_media_inner>
 
 
 <div id=page-content class=rich_media_area_primary>
 <div class=rich_media_area_primary_inner>
 
 
 
 <div id=img-content>
 
 <h2 class=rich_media_title id=activity-name>
 
 
 
 查询亿级数据毫秒级返回！牛逼哄哄的ElasticSearch是如何做到的？
 </h2>
 <div id=meta_content class=rich_media_meta_list>
 <span class="rich_media_meta rich_media_meta_text">
 中华石杉
 </span>
 
 <span class="rich_media_meta rich_media_meta_nickname" id=profileBt>
 <a href=https://mp.weixin.qq.com/s/nbelBO7xS15y_0MvPtS5OQ id=js_name>
 Java架构师之路 </a>
 <div id=js_profile_qrcode class=profile_container style=display:none>
 <div class=profile_inner>
 
 
 
 
 
 </div>
 <span class=profile_arrow_wrp id=js_profile_arrow_wrp>
 
 
 </span>
 </div>
 </span>
 <em id=publish_time class="rich_media_meta rich_media_meta_text">6月25日</em>
 </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 <div class=rich_media_content id=js_content>
 
 
 
 
 <blockquote data-type=2 data-url data-author-name data-content-utf8-length=32 data-source-title style=white-space:normal><section><p><span style=font-size:13px;color:#021eaa>作者：中华石杉&nbsp;</span><p><span style=font-size:13px;color:#021eaa>来源：石杉的架构笔记（ID:shishan100）</span></p></section></blockquote><p style=white-space:normal><br><section mpa-from-tpl=t><section style=border-width:0;border-style:initial;border-color:initial mpa-from-tpl=t><section style="margin-right:auto;margin-left:auto;margin-bottom:10px;border-bottom:1px solid #dddddd" mpa-from-tpl=t><section style="margin-bottom:-1px;padding-right:5px;padding-bottom:6px;padding-left:5px;clear:both;border-bottom:2px solid #ef7060;display:inline-block;line-height:1.1" mpa-from-tpl=t><p style=color:#000000;font-size:15px mpa-is-content=t><strong><span style=font-size:18px>目录：</span></strong></p></section></section></section><p><span style=font-size:14px>1. 一道面试题的引入：</span><br></p></section><p style=white-space:normal;line-height:2em><span style=font-size:14px>2. 性能优化的杀手锏：<strong>Filesystem Cache</strong></span><p style=white-space:normal;line-height:2em><span style=font-size:14px>3. 数据预热</span><p style=white-space:normal;line-height:2em><span style=font-size:14px>4. 冷热分离</span><p style=white-space:normal;line-height:2em><span style=font-size:14px>5.&nbsp;<strong>ElasticSearch&nbsp;</strong>中的关联查询</span><p style=white-space:normal;line-height:2em><span style=font-size:14px>6.&nbsp;<strong>Document&nbsp;</strong>模型设计</span><p style=white-space:normal;line-height:2em><span style=font-size:14px>7. 分页性能优化</span><p style=white-space:normal;line-height:2em><br><section mpa-from-tpl=t><section style=border-width:0;border-style:initial;border-color:initial mpa-from-tpl=t><section style="margin-right:auto;margin-left:auto;margin-bottom:10px;border-bottom:1px solid #dddddd" mpa-from-tpl=t><section style="margin-bottom:-1px;padding-right:5px;padding-bottom:6px;padding-left:5px;clear:both;border-bottom:2px solid #ef7060;display:inline-block;line-height:1.1" mpa-from-tpl=t><p style=color:#000000;font-size:15px mpa-is-content=t><span style=font-size:18px><strong>一道面试题的引入：</strong></span></p></section></section></section></section><p style=white-space:normal;line-height:2em><br><section powered-by=xiumi.us><blockquote data-type=2 data-url data-author-name data-content-utf8-length=45 data-source-title style=color:rgba(0,0,0,0.5)><section><p style=line-height:2em><span style=font-size:14px>如果面试的时候碰到这样一个面试题：ElasticSearch（以下简称ES） 在数据量很大的情况下（数十亿级别）如何提高查询效率？</span></p></section></blockquote></section><p><br><p><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;text-align:left;background-color:#ffffff;line-height:2em><span style=font-size:15px><span style=text-align:justify;color:#595959;letter-spacing:1px>这个问题说白了，就是看你有没有实际用过 ES，因为啥？</span><span style=text-align:justify;color:#595959;letter-spacing:1px;line-height:1.75em>其实 ES 性能并没有你想象中那么好的。</span><br></span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;line-height:1.75em;font-size:15px>很多时候数据量大了，特别是有几亿条数据的时候，可能你会懵逼的发现，跑个搜索怎么一下 5~10s，坑爹了。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>第一次搜索的时候，是 5~10s，后面反而就快了，可能就几百毫秒。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>然后你就很懵，每个用户第一次访问都会比较慢，比较卡么？所以你要是没玩儿过 ES，或者就是自己玩玩儿 Demo，被问到这个问题容易懵逼，显示出你对 ES 确实玩的不怎么样？</span><section data-tools=135编辑器 data-id=39 data-color=#138bde style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;line-height:27.2px;widows:1;background-color:#ffffff><section data-tools=135编辑器 data-id=39 data-color=#138bde data-custom=#1e9be8><section><p style=line-height:normal><br></p></section></section></section><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:15px><span style=color:#595959;letter-spacing:1px>说实话，ES 性能优化是没有银弹的。</span><span style=color:#595959;letter-spacing:1px;line-height:1.75em>啥意思呢？就是不要期待着随手调一个参数，就可以万能的应对所有的性能慢的场景。</span></span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;line-height:1.75em;font-size:15px>也许有的场景是你换个参数，或者调整一下语法，就可以搞定，但是绝对不是所有场景都可以这样。</span><p style=margin-right:8px;margin-left:8px;font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:normal><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:18px;color:#ab1942><strong><span style=letter-spacing:.544px></span></strong></span><section mpa-from-tpl=t><section style=border-width:0;border-style:initial;border-color:initial mpa-from-tpl=t><section style="margin-right:auto;margin-left:auto;margin-bottom:10px;border-bottom:1px solid #dddddd" mpa-from-tpl=t><section style="margin-bottom:-1px;padding-right:5px;padding-bottom:6px;padding-left:5px;clear:both;border-bottom:2px solid #ef7060;display:inline-block;line-height:1.1" mpa-from-tpl=t><p style=color:#000000;font-size:15px mpa-is-content=t><span style=font-size:18px><strong>性能优化的杀手锏：Filesystem Cache</strong></span></p></section></section></section></section><p style=margin-right:8px;margin-bottom:5px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>你往 ES 里写的数据，实际上都写到磁盘文件里去了，查询的时候，操作系统会将磁盘文件里的数据自动缓存到 Filesystem Cache 里面去。</span><br><p style=margin-right:8px;margin-bottom:5px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-bottom:5px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>整个过程，如下图所示：</span><p style=margin-right:8px;margin-bottom:5px;margin-left:8px;font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;text-align:center;background-color:#ffffff;line-height:normal><img class=rich_pages data-croporisrc="https://mmbiz.qpic.cn/mmbiz_jpg/tibrg3AoIJTtmGR5Eb1iaOWMib3auLw3FWrwkETy7ZYiaiaj4hLZvPnD8sQUFjFsKOSpoaKQT03cqh7L3SJABNpxaAA/?wx_fmt=jpeg" data-cropx1=0 data-cropx2=515 data-cropy1=44 data-cropy2=484 data-ratio=0.6666666666666666 data-s=300,640 data-type=jpeg data-w=515 data-src="https://mmbiz.qpic.cn/mmbiz_jpg/tibrg3AoIJTtmGR5Eb1iaOWMib3auLw3FWr3vOYdA7POCribHibIDQia3SbdPcaJDrAYQdMz7gqHuMeRicRrr5AiablonA/640?wx_fmt=jpeg" style="visibility:visible !important;width:515px !important;height:auto !important" _width=515px src="" crossorigin=anonymous data-fail=0><p style=margin-right:8px;margin-left:8px;font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:normal><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>ES 的搜索引擎严重依赖于底层的 Filesystem Cache，你如果给 Filesystem Cache 更多的内存，尽量让内存可以容纳所有的 IDX Segment File 索引数据文件，那么你搜索的时候就基本都是走内存的，性能会非常高。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#407600><strong><span style=font-size:15px;letter-spacing:1px>性能差距究竟可以有多大？</span></strong></span><span style=font-size:15px;color:#595959;letter-spacing:1px;line-height:1.75em>我们之前很多的测试和压测，如果走磁盘一般肯定上秒，搜索性能绝对是秒级别的，1 秒、5 秒、10 秒。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;line-height:1.75em;font-size:15px>但如果是走 Filesystem Cache，是走纯内存的，那么一般来说性能比走磁盘要高一个数量级，基本上就是毫秒级的，从几毫秒到几百毫秒不等。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:15px><span style=color:#595959;letter-spacing:1px>来看一个</span><strong><span style=color:#595959;letter-spacing:1px>真实的案例：</span></strong><span style=color:#595959;letter-spacing:1px;line-height:1.75em>某个公司 ES 节点有 3 台机器，每台机器看起来内存很多 64G，总内存就是 64 * 3 = 192G。</span></span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>每台机器给 ES JVM Heap 是 32G，那么剩下来留给 Filesystem Cache 的就是每台机器才 32G，总共集群里给 Filesystem Cache 的就是 32 * 3 = 96G 内存。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>而此时，整个磁盘上索引数据文件，在 3 台机器上一共占用了 1T 的磁盘容量，ES 数据量是 1T，那么每台机器的数据量是 300G。</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#407600><strong><span style=letter-spacing:1px;font-size:15px>这样性能好吗？&nbsp;</span></strong></span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>Filesystem Cache 的内存才 100G，十分之一的数据可以放内存，其他的都在磁盘，然后你执行搜索操作，大部分操作都是走磁盘，性能肯定差。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>归根结底，你要让 ES 性能好，<strong><span style=color:#c9381c>最佳的情况下，就是你的机器的内存，至少可以容纳你的总数据量的一半。</span></strong></span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>根据我们自己的生产环境实践经验，最佳的情况下，是仅仅在 ES 中就存少量的数据。</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>也就是说，你要用来搜索的那些索引，如果内存留给 Filesystem Cache 的是 100G，那么你就将索引数据控制在 100G 以内。</span><span style=color:#595959;font-size:15px;letter-spacing:1px>这样的话，你的数据几乎全部走内存来搜索，性能非常之高，一般可以在1秒以内。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>比如说你现在有一行数据：id，name，age .... 30 个字段。但是你现在搜索，只需要根据 id，name，age 三个字段来搜索。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>如果你傻乎乎往 ES 里写入一行数据所有的字段，就会导致 90% 的数据是不用来搜索的。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>但是呢，这些数据硬是占据了 ES 机器上的 Filesystem Cache 的空间，单条数据的数据量越大，就会导致 Filesystem Cahce 能缓存的数据就越少。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>其实，仅仅写入 ES 中要用来检索的少数几个字段就可以了，比如说就写入 es id，name，age 三个字段。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>然后你可以把其他的字段数据存在 MySQL/HBase 里，我们一般是建议用&nbsp;<strong><span style=color:#c9381c>ES + HBase</span></strong>&nbsp;这么一个架构。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>HBase是列式数据库，其特点是适用于海量数据的在线存储，就是对 HBase 可以写入海量数据，但是不要做复杂的搜索，做很简单的一些根据 id 或者范围进行查询的这么一个操作就可以了。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>从 ES 中根据 name 和 age 去搜索，拿到的结果可能就 20 个 doc id，然后根据 doc id 到 HBase 里去查询每个 doc id 对应的完整的数据，给查出来，再返回给前端。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>而写入 ES 的数据最好小于等于，或者是略微大于 ES 的 Filesystem Cache 的内存容量。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>然后你从 ES 检索可能就花费 20ms，然后再根据 ES 返回的 id 去 HBase 里查询，查 20 条数据，可能也就耗费个 30ms。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>如果你像原来那么玩儿，1T 数据都放 ES，可能会每次查询都是 5~10s，而现在性能就会很高，每次查询就是 50ms。</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px><br></span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:18px;color:#ab1942><strong><span style=letter-spacing:1px></span></strong></span><section mpa-from-tpl=t><section style=border-width:0;border-style:initial;border-color:initial mpa-from-tpl=t><section style="margin-right:auto;margin-left:auto;margin-bottom:10px;border-bottom:1px solid #dddddd" mpa-from-tpl=t><section style="margin-bottom:-1px;padding-right:5px;padding-bottom:6px;padding-left:5px;clear:both;border-bottom:2px solid #ef7060;display:inline-block;line-height:1.1" mpa-from-tpl=t><p style=color:#000000;font-size:15px mpa-is-content=t><span style=font-size:18px><strong>数据预热</strong></span></p></section></section></section></section><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>假如你就按照上述的方案去做了，ES 集群中每个机器写入的数据量还是超过了 Filesystem Cache 一倍。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>比如说你写入一台机器 60G 数据，结果 Filesystem Cache 就 30G，还是有 30G 数据留在了磁盘上。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:15px><span style=color:#595959;letter-spacing:1px>这种情况下，其实可以做<strong>数据预热</strong>。</span><span style=color:#595959;letter-spacing:1px;line-height:1.75em>举个例子，拿微博来说，你可以把一些大 V，平时看的人很多的数据，提前在后台搞个系统。</span></span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;line-height:1.75em;font-size:15px>然后每隔一会儿，自己的后台系统去搜索一下热数据，刷到 Filesystem Cache 里去，后面用户实际上来看这个热数据的时候，他们就是直接从内存里搜索了，很快。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>或者是电商，你可以将平时查看最多的一些商品，比如说 iPhone 8，热数据提前后台搞个程序，每隔 1 分钟自己主动访问一次，刷到 Filesystem Cache 里去。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>总之，就是对于那些你觉得比较热的、经常会有人访问的数据，最好做一个专门的缓存预热子系统。</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;font-size:15px;letter-spacing:1px>然后对热数据每隔一段时间，就提前访问一下，让数据进入 Filesystem Cache 里面去。这样下次别人访问的时候，性能一定会好很多。</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:18px;color:#ab1942><strong><span style=letter-spacing:1px></span></strong></span><section mpa-from-tpl=t><section style=border-width:0;border-style:initial;border-color:initial mpa-from-tpl=t><section style="margin-right:auto;margin-left:auto;margin-bottom:10px;border-bottom:1px solid #dddddd" mpa-from-tpl=t><section style="margin-bottom:-1px;padding-right:5px;padding-bottom:6px;padding-left:5px;clear:both;border-bottom:2px solid #ef7060;display:inline-block;line-height:1.1" mpa-from-tpl=t><p style=color:#000000;font-size:15px mpa-is-content=t><span style=font-size:18px><strong>冷热分离</strong></span></p></section></section></section></section><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>ES 可以做类似于 MySQL 的水平拆分，就是说将大量的访问很少、频率很低的数据，单独写一个索引，然后将访问很频繁的热数据单独写一个索引。</span><br><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>最好是将冷数据写入一个索引中，然后热数据写入另外一个索引中，这样可以确保热数据在被预热之后，尽量都让他们留在 Filesystem OS Cache 里，别让冷数据给冲刷掉。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>还是来一个例子，假设你有 6 台机器，2 个索引，一个放冷数据，一个放热数据，每个索引 3 个 Shard。3 台机器放热数据 Index，另外 3 台机器放冷数据 Index。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>这样的话，你大量的时间是在访问热数据 Index，热数据可能就占总数据量的 10%，此时数据量很少，几乎全都保留在 Filesystem Cache 里面了，就可以确保热数据的访问性能是很高的。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>但是对于冷数据而言，是在别的 Index 里的，跟热数据 Index 不在相同的机器上，大家互相之间都没什么联系了。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>如果有人访问冷数据，可能大量数据是在磁盘上的，此时性能差点，就 10% 的人去访问冷数据，90% 的人在访问热数据，也无所谓了。</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#ab1942><strong><span style=font-size:18px></span></strong></span><section mpa-from-tpl=t><section style=border-width:0;border-style:initial;border-color:initial mpa-from-tpl=t><section style="margin-right:auto;margin-left:auto;margin-bottom:10px;border-bottom:1px solid #dddddd" mpa-from-tpl=t><section style="margin-bottom:-1px;padding-right:5px;padding-bottom:6px;padding-left:5px;clear:both;border-bottom:2px solid #ef7060;display:inline-block;line-height:1.1" mpa-from-tpl=t><p style=color:#000000;font-size:15px mpa-is-content=t><span style=font-size:18px><strong>ES中的关联查询</strong></span></p></section></section></section><p><br mpa-from-tpl=t></p></section><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>对于 MySQL，我们经常有一些复杂的关联查询，在 ES 里该怎么玩儿？</span><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>ES 里面的复杂的关联查询尽量别用，一旦用了性能一般都不太好。</span><span style=color:#595959;font-size:15px;letter-spacing:1px>最好是先在 Java 系统里就完成关联，将关联好的数据直接写入 ES 中。搜索的时候，就不需要利用 ES 的搜索语法来完成 Join 之类的关联搜索了。</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;font-size:15px;letter-spacing:1px><br></span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:18px;color:#ab1942><strong><span style=letter-spacing:.544px></span></strong></span><section mpa-from-tpl=t><section style=border-width:0;border-style:initial;border-color:initial mpa-from-tpl=t><section style="margin-right:auto;margin-left:auto;margin-bottom:10px;border-bottom:1px solid #dddddd" mpa-from-tpl=t><section style="margin-bottom:-1px;padding-right:5px;padding-bottom:6px;padding-left:5px;clear:both;border-bottom:2px solid #ef7060;display:inline-block;line-height:1.1" mpa-from-tpl=t><p style=color:#000000;font-size:15px mpa-is-content=t><span style=font-size:18px><strong>Document 模型设计</strong></span></p></section></section></section></section><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>Document 模型设计是非常重要的，很多操作，不要在搜索的时候才想去执行各种复杂的乱七八糟的操作。</span><br><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>ES 能支持的操作就那么多，不要考虑用 ES 做一些它不好操作的事情。如果真的有那种操作，尽量在 Document 模型设计的时候，写入的时候就完成。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>另外对于一些太复杂的操作，比如 join/nested/parent-child 搜索都要尽量避免，性能都很差的。</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:18px;color:#ab1942><strong><span style=letter-spacing:.544px></span></strong></span><section mpa-from-tpl=t><section style=border-width:0;border-style:initial;border-color:initial mpa-from-tpl=t><section style="margin-right:auto;margin-left:auto;margin-bottom:10px;border-bottom:1px solid #dddddd" mpa-from-tpl=t><section style="margin-bottom:-1px;padding-right:5px;padding-bottom:6px;padding-left:5px;clear:both;border-bottom:2px solid #ef7060;display:inline-block;line-height:1.1" mpa-from-tpl=t><p style=color:#000000;font-size:15px mpa-is-content=t><span style=font-size:18px><strong>分页性能优化</strong></span></p></section></section></section></section><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:15px;color:#595959;letter-spacing:1px>ES 的分页是较坑的，为啥呢？</span><span style=font-size:15px;color:#595959;letter-spacing:1px;line-height:1.75em>举个例子吧，假如你每页是 10 条数据，你现在要查询第 100 页，实际上是会把每个 Shard 上存储的前 1000 条数据都查到一个协调节点上。</span><br><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;line-height:1.75em;font-size:15px>如果你有 5 个 Shard，那么就有 5000 条数据，接着协调节点对这 5000 条数据进行一些合并、处理，再获取到最终第 100 页的 10 条数据。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>由于是分布式的，你要查第 100 页的 10 条数据，不可能说从 5 个 Shard，每个 Shard 就查 2 条数据，最后到协调节点合并成 10 条数据吧？</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>你必须得从每个 Shard 都查 1000 条数据过来，然后根据你的需求进行排序、筛选等等操作，最后再次分页，拿到里面第 100 页的数据。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>你翻页的时候，翻的越深，每个 Shard 返回的数据就越多，而且协调节点处理的时间越长，非常坑爹。所以用 ES 做分页的时候，你会发现越翻到后面，就越是慢。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>我们之前也是遇到过这个问题，用 ES 作分页，前几页就几十毫秒，翻到 10 页或者几十页的时候，基本上就要 5~10 秒才能查出来一页数据了。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:15px;color:#595959;letter-spacing:1px>有什么解决方案吗？两个思路：</span><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:15px;color:#595959;letter-spacing:1px;line-height:1.75em>一、不允许深度分页（默认深度分页性能很差）。跟产品经理说，你系统不允许翻那么深的页，默认翻的越深，性能就越差。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=font-size:15px><span style=color:#595959;letter-spacing:1px>二、类似于 App 里的推荐商品不断下拉出来一页一页的；</span><span style=color:#595959;letter-spacing:1px;line-height:1.75em>类似于微博中，下拉刷微博，刷出来一页一页的，你可以用 Scroll API，关于如何使用，大家可以自行上网搜索学习一下。</span></span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>Scroll是如何做的呢？它会一次性给你生成所有数据的一个快照，然后每次滑动向后翻页就是通过游标 scroll_id 移动，获取下一页、下一页这样子，性能会比上面说的那种分页性能要高很多很多，基本上都是毫秒级的。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>但是，唯一的一点就是，这个适合于那种类似微博下拉翻页的，不能随意跳到任何一页的场景。</span><span style=color:#595959;font-size:15px;letter-spacing:1px>也就是说，你不能先进入第 10 页，然后去第 120 页，然后又回到第 58 页，不能随意乱跳页。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>所以现在很多产品，都是不允许你随意翻页的，你只能往下拉，一页一页的翻。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>使用时需要注意，初始化必须指定 Scroll 参数，告诉 ES 要保存此次搜索的上下文多长时间。你需要确保用户不会持续不断翻页翻几个小时，否则可能因为超时而失败。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>除了用 Scroll API，你也可以用 search_after 来做。search_after 的思想是使用前一页的结果来帮助检索下一页的数据。</span><p style=font-variant-numeric:normal;font-variant-east-asian:normal;white-space:normal;letter-spacing:.544px;widows:1;line-height:normal;background-color:#ffffff><br><p style=margin-right:8px;margin-left:8px;white-space:normal;font-variant-numeric:normal;letter-spacing:.544px;widows:1;background-color:#ffffff;line-height:2em><span style=color:#595959;letter-spacing:1px;font-size:15px>显然，这种方式也不允许你随意翻页，你只能一页页往后翻。初始化时，需要使用一个唯一值的字段作为 Sort 字段。</span><p style=white-space:normal><br><p style=white-space:normal;letter-spacing:.544px;background-color:#ffffff;text-align:left;line-height:2em><strong><span style=font-size:15px;letter-spacing:1px;font-family:宋体,SimSun;color:#ab1942>【推荐阅读<strong style=letter-spacing:.544px><span style=letter-spacing:1px>】</span></strong></span></strong><p style=white-space:normal;letter-spacing:.544px;background-color:#ffffff><a href="https://mp.weixin.qq.com/s?__biz=MzI3NjU2ODA5Mg==&amp;mid=2247484565&amp;idx=2&amp;sn=6cc229f530f3961f80d9f1208deff427&amp;scene=21#wechat_redirect" target=_blank data-linktype=2 style=-webkit-tap-highlight-color:rgba(0,0,0,0)><span style=-webkit-tap-highlight-color:rgba(0,0,0,0);color:#021eaa;font-size:14px>[技术]：IDEA中用好Lombok，撸码效率至少提升5倍</span></a><p style=white-space:normal;letter-spacing:.544px;background-color:#ffffff><a href="https://mp.weixin.qq.com/s?__biz=MzI3NjU2ODA5Mg==&amp;mid=2247484577&amp;idx=2&amp;sn=1b00ee24aeece32e883dfecd9bc9daed&amp;scene=21#wechat_redirect" target=_blank data-linktype=2 style=-webkit-tap-highlight-color:rgba(0,0,0,0)><span style=-webkit-tap-highlight-color:rgba(0,0,0,0);color:#021eaa;font-size:14px>[技术]：关于MQ，你必须懂得的</span></a><p style=white-space:normal;letter-spacing:.544px;background-color:#ffffff><a href="https://mp.weixin.qq.com/s?__biz=MzI3NjU2ODA5Mg==&amp;mid=2247484591&amp;idx=2&amp;sn=f840a1ccfa3ab77a8df92a15496944a8&amp;scene=21#wechat_redirect" target=_blank data-linktype=2><span style=-webkit-tap-highlight-color:rgba(0,0,0,0);color:#021eaa;font-size:14px>[技术]：千万并发，阿里淘宝的 14 次架构演进之路！</span></a><p style=white-space:normal;letter-spacing:.544px;background-color:#ffffff;text-align:left><a href="https://mp.weixin.qq.com/s?__biz=MzI3NjU2ODA5Mg==&amp;mid=2247484591&amp;idx=1&amp;sn=cbd82df03fd27597b8e686b3ff3850e6&amp;scene=21#wechat_redirect" target=_blank data-linktype=2><span style=-webkit-tap-highlight-color:rgba(0,0,0,0);color:#021eaa;font-size:14px></span></a><p style=white-space:normal;letter-spacing:.544px;background-color:#ffffff;text-align:left><br><p style=white-space:normal;letter-spacing:.544px;background-color:#ffffff;text-align:left><img data-type=jpeg data-ratio=0.3333333333333333 data-w=1080 data-backw=556 data-backh=186 data-before-oversubscription-url="https://mmbiz.qpic.cn/mmbiz_jpg/M7B64fHXIStj2G1ryBlfibourJLibdiaATePdUl76gZQ2VEHHRIcLrKgYXCTOVc71xYXgS9QvmibTcnm56xDnKoBhQ/640?wx_fmt=jpeg" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/M7B64fHXIStj2G1ryBlfibourJLibdiaATePdUl76gZQ2VEHHRIcLrKgYXCTOVc71xYXgS9QvmibTcnm56xDnKoBhQ/640?wx_fmt=jpeg" style="visibility:visible !important;width:677px !important;height:auto !important" _width=677px src="" crossorigin=anonymous data-fail=0></p>
 </div>
 
 
 <div class=ct_mpda_wrp id=js_sponsor_ad_area style=display:none></div>
 
 <div class=read-more__area id=js_more_read_area style=display:none>
 
 </div>
 </div>
 
 <div class="article_modify_area tips_global_primary article_modify_area_primary">
 文章已于<span id=js_modify_time>2019-06-27</span>修改 </div>
 
 
 <ul id=js_hotspot_area class=article_extend_area></ul>
 
 
<div class=rich_media_tool id=js_toobar3>
 <div class=weui-flex>
 <div class=weui-flex__item>
 
 <a class="media_tool_meta meta_primary" id=js_view_source href=##>阅读原文</a>
 <div id=js_read_area3 class="media_tool_meta tips_global_primary meta_primary" style=display:none>
 <span id=readTxt>阅读</span>
 <span id=readNum3></span>
 </div>
 </div>
 <span style=display:none class="media_tool_meta meta_extra meta_praise" id=like_old>
 <i class=icon_praise_gray></i><span class=praise_num id=likeNum_old></span>
 </span>
 
 <span style=visibility:hidden class="media_tool_meta meta_extra meta_like" id=like3>
 <button class=like_btn id=js_like_btn> 
 <span id=js_like_wording> 在看</span><span class=like_num id=likeNum3></span>
 </button>
 </span>
 
 </div>
</div>
 
 <div class=like_comment_wrp id=js_like_comment style=display:none>
 <div class=like_comment_inner>
 
 
 </div>
 </div> 
 <div style=display:none id=wow_close_inform>
 <div class=weui-mask></div>
 <div class=weui-dialog>
 
 
 
 </div>
 </div>
<div id=js_like_toast style=display:none>
 <div class=weui-mask_transparent></div>
 <div class=weui-toast>
 
 
 </div>
</div>
<div style=display:none id=js_comment_panel>
 <div class="like_comment_primary_wrp editing" id=js_comment_wrp>
 
 </div> 
 <div class=like_comment_primary_mask id=js_mask_2></div>
</div>
<div id=js_loading style=display:none>
 <div class=weui-mask_transparent></div>
 <div class=weui-toast>
 
 
 </div>
</div>
 </div>
 </div>
 <div class="rich_media_area_primary sougou" id=sg_tj style=display:none></div>
 
 <div class=rich_media_area_extra>
 <div class=rich_media_area_extra_inner>
 
 <div id=js_share_appmsg>
 </div>
 
 
 <div class=mpda_bottom_container id=js_bottom_ad_area style=display:none></div>
 
 <div id=js_iframetest style=display:none></div>
 
 <div class="rich_media_extra rich_media_extra_discuss" id=js_cmt_container style=display:none>
 
 
 <div class=discuss_mod id=js_friend_cmt_area style=display:none>
 
 
 
 </div>
 <div class=discuss_mod id=js_cmt_area style=display:none>
 </div>
 </div>
 </div>
 </div>
 
 <div id=js_pc_qr_code class=qr_code_pc_outer style=display:block;>
 <div class=qr_code_pc_inner>
 <div class=qr_code_pc>
 <img id=js_pc_qr_code_img class=qr_code_pc_img src="">
 <p>微信扫一扫<br>关注该公众号</p>
 </div>
 </div>
 </div>
 </div>
</div>
<div id=js_pc_weapp_code class="weui-desktop-popover weui-desktop-popover_pos-up-center weui-desktop-popover_img-text" style=display:none>
 <div class=weui-desktop-popover__content>
 
 </div>
</div>
<div id=js_minipro_dialog style=display:none>
 <div class=weui-mask></div>
 <div class="weui-dialog weui-dialog_link">
 
 
 
 
 </div>
</div>
<div id=js_link_dialog style=display:none>
 <div class=weui-mask></div>
 <div class="weui-dialog weui-dialog_link">
 
 
 
 
 </div>
</div>
<div class=comment_primary_emotion_panel_wrp id=js_emotion_panel_pc style=display:none>
 <div class=comment_primary_emotion_panel>
 
 </div>
</div>
<div class=weui-dialog__wrp id=js_alert_panel style=display:none>
 <div class=weui-mask></div>
 <div class=weui-dialog>
 
 
 </div>
</div>
<div id=js_weapp_without_auth_dialog style=display:none>
 <div class=weui-mask></div>
 <div class="weui-dialog weui-dialog_link">
 
 
 </div>
</div>
 
 
 
 
 
 
